<?php
namespace app\admin\controller;

use think\Controller;
use think\Session;
use think\Request;
use app\admin\model\CountersModel;

class Counters extends Common
{
	/**
	*	前台会员申请专柜列表
	*/
	public function index()
	{
		$data = $this->request->param();
		$CountersModel = new CountersModel();
		$list = $CountersModel->getCounters($data);
		// 获取分页显示
	    $page = $list->render();
	    $this->assign('page',$page);
		$this->assign('list',$list);

		$this->assign('u_name',isset($data['u_name']) ? $data['u_name'] : '');
		$this->assign('c_name',isset($data['c_name']) ? $data['c_name'] : '');
		$this->assign('c_card',isset($data['c_card']) ? $data['c_card'] : '');
		$this->assign('c_tel',isset($data['c_tel']) ? $data['c_tel'] : '');
		$this->assign('keyword',isset($data['keyword']) ? $data['keyword'] : '');
		$this->assign('c_status',isset($data['c_status']) ? $data['c_status'] : '');
		return $this->fetch();
	}


	/**
	*	修改专柜申请信息
	*/
	public function edit()
	{
		$data = $this->request->param();

		if($data){
			$CountersModel = new CountersModel();
			$list = $CountersModel->getOne($data['id']);
			$post = [];
			//把pc中的图片json转为数组
			$post = json_decode($list['c_pic'],true);
			$this->assign('post',$post);
			$this->assign('list',$list);
		}
		return $this->fetch();
	}

	/**
	*	修改专柜申请信息提交
	*/
	public function editPost()
	{
		if ($this->request->isPost()) {
			$data = $this->request->param();

			$CountersModel = new CountersModel();

	        $list = $CountersModel->editCounters($data['id'],$data);

	        $this->success('修改成功');
        }
	}

	/**
	*	删除合伙人申请福利
	*/
	public function delete()
	{
		$data = $this->request->param();
		if($data){
			$CountersModel = new CountersModel();

			$list = $CountersModel->deleteCounters($data['id']);

			if($list){
				$this->success('删除成功',url('/admin/Counters/index'));

			}else{
				$this->error('删除失败',url('/admin/Counters/index'));
			}
		}
	}



	/**
	*	专柜申请福利列表
	*/
	public function welfare()
	{
		$CountersModel = new CountersModel();
		$list = $CountersModel->getWelfare();
		$this->assign('list',$list);
		return $this->fetch();
	}

	/**
	*	添加专柜申请福利
	*/
	public function addwelfare()
	{
		return $this->fetch();
	}

	/**
	*	添加专柜申请福利提交
	*/
	public function addwelfarePost()
	{
		if ($this->request->isPost()) {
			$data = $this->request->param();

			$CountersModel = new CountersModel();

	        $list = $CountersModel->addwelfarePost($data);

	        if ($list){
	        	$this->success('添加成功');
	        }else{
	        	$this->error('专柜申请协议已存在,请不要重复添加');
	        }
        }
	}

	/**
	*	修改专柜申请福利
	*/
	public function editwelfare()
	{
		$data = $this->request->param();
		$CountersModel = new CountersModel();
		$list = $CountersModel->getOneWelfare($data['id']);
		$this->assign('list',$list);

		return $this->fetch();
	}

	/**
	*	修改专柜申请福利提交
	*/
	public function editwelfarePost()
	{
		if ($this->request->isPost()) {
			$data = $this->request->param();

			$CountersModel = new CountersModel();

	        $list = $CountersModel->editWelfarePost($data['id'],$data);

	        $this->success('修改成功');
        }

	}

	/**
	*	删除专柜申请福利
	*/
	public function deletewelfare()
	{
		$data = $this->request->param();
		if($data){
			$CountersModel = new CountersModel();
			$list = $CountersModel->deleteWelfare($data['id']);
			if($list){
				$this->success('删除成功',url('/admin/Counters/welfare'));

			}else{
				
				$this->error('删除失败',url('/admin/Counters/welfare'));	
			}
		}
	}
}
